﻿using System;
using KamRemakeRemake.Common;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace KamRemakeRemake.GUI {
    public class Button : IDrawableGameObject {
        public event EventHandler Click;
        private SpriteFont font;

        public string Text { get; set; }
        public Rectangle Position { get; set; }

        public Button(string text, Rectangle position) {
            this.Text = text;
            this.Position = position;
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch, ContentManager contentManager) {
            spriteBatch.DrawString(font, this.Text, new Vector2(this.Position.Left,this.Position.Top), Color.White);
        }

        public void LoadContent(ContentManager contentManager) {
            this.font = contentManager.Load<SpriteFont>("fonts/menu");
        }

        public void Update(GameTime gameTime) {
            if (this.Position.Intersects(Cursor.Instance.ScreenRectangle)) {
                MouseState mouseState = Mouse.GetState();
                if (mouseState.LeftButton == ButtonState.Pressed) {
                    if (this.Click != null)
                        this.Click(this, null); 
                }
            }
        }
    }
}
